import { User } from "../models/user";

// 把注册信息写入数据库
const registerUser = async (ctx: any) => {
  const { userName, password } = ctx.request.body;
  const user = await User
    .findOne({ userName });
  if (user) {
    return  {
      code: 0,
      message: "用户名已存在"
    };
  }
  await new User({
    userName,
    password,
  }).save();
  return {
    code: 200,
    message: "注册成功"
  };
}
export default registerUser;